home *** CD-ROM | disk | FTP | other *** search
-
- *****Coeff_Cubic (Listing 1)*****
-
-
- void coeff_cubic (a,p,q,x,y,lambda,k)
- /*
- * Set up the equations for the Hermite cubic approximation.
- */
- double *a,*x,*y,*lambda;
- int p,q,k;
- {
- double d,alpha,beta,d3,alpha3;
- int i,j,col;
- for (i=0; i<p; i++)
- {
- j = interval (lambda,x[i],k);
- col = SUB(i,2*(j-1),q);
- d = lambda[j] - lambda[j-1];
- alpha = x[i]-lambda[j-1];
- beta = d-alpha;
- d3 = d*d*d;
- alpha3 = alpha*alpha*alpha;
- *(a+col) = (d3-3.0*d*alpha*alpha+2.0*alpha3)/d3;
- *(a+col+1) = d*alpha*beta*beta/d3;
- *(a+col+2) = (3.0*d-2.0*alpha)*alpha*alpha/d3;
- *(a+col+3) = -d*alpha*alpha*beta/d3;
- }
- }
-
- int interval (x,v,n)
- /*
- * Given a value v find the interval j such that v is in the interval
- * x[j-1] to x[j], where x is an increasing set of n values.
- */
- double x[],v;
- int n;
- {
- int j = 0, found = 0;
- if (v == x[0]) return(1);
- while (!found && ++j<n)
- found =( v<=x[j] && v> x[j-1]) ? 1:0;
- return(j);
- }
-
-
-
-
- double app_cubic (x,j,lambda,res)
- /*
- * Given the result res[] from the routine Hermite() find the value
- * of y for the given x value.
- */
- double x,*lambda,*res;
- int j;
- {
- double d,alpha,beta,d3,alpha3,sum,val[4];
- int i,col;
- col = 2*(j-1);
- d = lambda[j] - lambda[j-1];
- alpha = x-lambda[j-1];
- beta = d-alpha;
- d3 = d*d*d;
- alpha3 = alpha*alpha*alpha;
- val[0] = (d3-3.0*d*alpha*alpha+2.0*alpha3)/d3;
- val[1] = d*alpha*beta*beta/d3;
- val[2] = (3.0*d-2.0*alpha)*alpha*alpha/d3;
- val[3] = -d*alpha*alpha*beta/d3;
- for (sum=0.0,i=0; i<4; i++) sum += val[i]*res[col+i];
- return (sum);
- }
-
-
-
-
-
-
-